//
//  NotificationsTableController.m
//  UIElementInspector
//
//  Copyright 2012 Google Inc. All Rights Reserved.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.

#import "NotificationsTableController.h"
#import "Preferences.h"

@implementation NotificationsTableController

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
    NSArray *notifications = [[Preferences sharedPreferences] allNotifications];
    return [notifications count];
}

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    NSArray *notifications = [[Preferences sharedPreferences] allNotifications];
    id notification = [notifications objectAtIndex:row];
    if ([[Preferences sharedPreferences] isNotificationEnabled:(NSString*) notification])
        return @"1";
    else
        return @"0";
}

- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    NSArray *notifications = [[Preferences sharedPreferences] allNotifications];
    NSButtonCell *retval = [[NSButtonCell alloc] init];
    [retval setButtonType:NSSwitchButton];
    [retval setTitle:[notifications objectAtIndex:row]];
    return retval;
}

- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
    NSArray *notifications = [[Preferences sharedPreferences] allNotifications];
    id notification = [notifications objectAtIndex:rowIndex];
    [[Preferences sharedPreferences] setNotification:notification enabled:[(NSString*) anObject integerValue]];
}

@end
